<template>
    <div class='home-container chooseClass-page'>
        <div class="right-content white-color chooseClass">
            <div class="title">
                <img src="../../src/assets/img/welcome/book.png" alt="" class=''>
                <span>选择班级</span>
                <img src="../../src/assets/img/welcome/close.png" alt="" class=' close-btn' @click="goBack">
            </div>
            <div class="search-contain">
                <el-form :inline="true" :model="form" class="demo-form-inline">
                    <el-form-item label="学科">
                        <el-select v-model="form.subject" placeholder="全部" class="status-input el-select-common">
                            <el-option v-for="item in subjectList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="班级">
                        <el-input v-model="form.name" placeholder="班级" class="static-input">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="讲师">
                        <el-select v-model="form.lecturer" placeholder="全部" class="status-input el-select-common">
                            <el-option v-for="item in teacherList" :key="item.id" :label="item.realname" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="助教">
                        <el-select v-model="form.assistant" placeholder="全部" class="status-input el-select-common">
                            <el-option v-for="item in assistantList" :key="item.id" :label="item.realname" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">查询</el-button>
                        <el-button @click="resetForm()">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div class="content-contain">
                <el-table :data="tableData" style="width: 100%"
                    :header-cell-style="{background:'#EFF1F6',color:'#1C1C1C'}" stripe>
                    <el-table-column label="开课日期" prop="begindate">
                    </el-table-column>
                    <el-table-column label="结课日期" prop="enddate">
                    </el-table-column>
                    <el-table-column label="班级" prop="name">
                    </el-table-column>
                    <el-table-column label="课程类型" prop="type">
                    </el-table-column>
                    <el-table-column label="学科" prop="subjectname">
                    </el-table-column>
                    <el-table-column label="讲师" prop="lecturername">
                    </el-table-column>
                    <el-table-column label="助教" prop="assistantname">
                    </el-table-column>
                    <el-table-column label="选择班级">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="chooseClass(scope.row)">选择</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="footer-contain">
                <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                               :page-sizes="[20, 50, 100, 200]" :page-size="pagesize"
                               layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
                <div class='go-page'>确定</div>
            </div>
        </div>
    </div>
</template>

<script>
import {
    getClassPage
} from '@/api/classList'
import { getSubjectList } from '@/api/subjectList'
import { getStudentClass } from '@/api/studentList'
import { getTeacherList } from '@/api/teachList'
export default {
    name: 'home',
    data() {
        return {
            headerList: ['会员', '班级', '班级列表'],
            openeds: ['5', '5-2'],
            activeTab: 'Member',
            form: {
                subject: '',
                name: '',
                lecturer: '',
                assistant: ''
            },
            page: 1,
            pagesize: 10,
            total: 0,
            tableData: [],
            subjectList: [],
            teacherList: [],
            assistantList: [],
            student: this.$route.query.student,
            type: this.$route.query.type
        }
    },
    mounted() {
        this.getClassPage()
        this.getSubjectList()
        this.getTeacherList()
    },
    methods: {
        getSubjectList() {
            getSubjectList({}).then(res => {
                if (res.code == 1) {
                    this.subjectList = res.data
                }
            })
        },
        getTeacherList() {
            getTeacherList({}).then(res => {
                if (res.code == 1) {
                    let data = res.data || []
                    data.forEach(item => {
                        if(item.type === 2) {
                            this.teacherList.push(item)
                        }else if(item.type === 3) {
                            this.assistantList.push(item)
                        }
                    })
                }
            })
        },
        getClassPage() {
            getClassPage({
                page: this.page,
                pagesize: this.pagesize,
                subject: this.form.subject,
                name: this.form.name,
                lecturer: this.form.lecturer,
                assistant: this.form.assistant,
                estudent: this.id
            }).then(res => {
                if (res.code == 1) {
                    this.tableData = res.data.list
                    this.total = res.data.recordcount
                }
            })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`)
            this.pagesize = val
            this.getClassPage()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`)
            this.page = val
            this.getClassPage()
        },
        handleEdit(index, row) {
            console.log(index, row)
        },
        handleDelete(index, row) {
            console.log(index, row)
        },
        onSubmit() {
            this.getClassPage()
        },
        resetForm() {
            this.form.name = ''
            this.form.subject = ''
            this.form.lecturer = ''
            this.form.assistant = ''
            this.page = 1
            this.pagesize = 10
            this.getClassPage()
        },
        handleOpen(key, keyPath) {
            console.log(key, keyPath)
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath)
        },
        /**
             * 选班级注意url有没有type参数来区别不同业务
             * type：1 来自学生列表需请求接口
             * type：2 来至直播只需带班级id回去原页面
             * @param item
             */
        chooseClass(item) {
            this.$confirm('选择' + item.name + '，请确认？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                if(this.type === 1) {
                    this.getStudentClass(item)
                }else if(this.type === 2) {
                    this.$router.push({
                        path: '/addLargeClass', //跳转的路径
                        query: {
                            classId: item.id,
                            className: item.name,
                            lecturerName: item.lecturername,
                            assistantName: item.assistantname
                        }
                    })
                }
            }).catch(() => {

            })
        },
        getStudentClass(item) {
            getStudentClass({
                'student': this.student,
                'class': item.id
            }).then(res => {
                if (res.code == 1) {
                    this.$message({
                        message: res.message,
                        type: 'success'
                    })
                    this.$router.push('/studentList')
                }
            })
        },
        goBack() {
            this.$router.go(-1)
        }
    },
    components: {}
}

</script>
<style lang="less" scoped>
    @import url('../../src/assets/less/Mixins.less');
    @import url('../../src/assets/less/common.less');

    html,
    body {
        height: 100%
    }

    .chooseClass-page {
        background: rgba(238, 244, 249, 1)
    }

    .search-contain {
        // margin-top: 20px;
        padding-left: 20px;
        padding-top: 24px;
    }

    .content-contain {
        // padding-left: 16px;
    }

    .right-container {
        background: #ffffff;
        height: 100%;
    }

    .operate {
        cursor: pointer;
        margin-right: 20px;

        img {
            width: 16px;
            height: 16px;
        }
    }

    .grid-content {
        span {
            position: relative;
            margin-right: 5px;
            top: 3px;
        }
    }

    .white-color {
        background: rgba(255, 255, 255, 1);
        box-shadow: 0px 0px 0px 0px rgba(119, 151, 178, 0.16);
        border-radius: 4px;
        height: calc(100% - 50px);
        width: calc(100% - 60px);

        margin: auto;

        .title {
            width: 100%;
            height: 56px;
            border-bottom: solid 1px #E8E9EA;
            line-height: 56px;

            img {
                margin-left: 24px;
                margin-right: 16px;
                position: relative;
                top: 2px;
                width: 20px;
                height: 20px;
                border-radius: 1px;

            }

            span {
                font-size: 20px;
                font-family: PingFang-SC-Regular;
                font-weight: 400;
                color: rgba(28, 28, 28, 1);

            }

            .close-btn {
                float: right;
                margin-right: 15px;
                cursor: pointer;
                margin-top: 18px
            }
        }
    }

    .home-container {
        padding-top: 20px;
    }

</style>
<style lang="less">
    .el-table {
        border: 1px solid rgba(223, 230, 236, 1) !important;
        border-bottom: none !important;
    }

    .el-table__header-wrapper {
        height: 40px !important;
        background: rgba(239, 241, 246, 1) !important;
    }

    .el-table__header tr,
    .el-table__header th {
        padding: 0 !important;
        height: 40px !important;
    }

    .el-table__body-wrapper {
        .el-row {
            margin-bottom: 16px !important;

            &:first-child {
                margin-top: 10px !important;
            }
        }

        tbody {

            .table__row,
            td {
                padding: 8px 0px !important;

            }

        }
    }

    .static-input {
        width: 150px !important;
        height: 40px !important;
    }

    /*.el-form-item__content {*/
    /*    margin-right: 20px*/
    /*}*/
    // 分页样式
    .el-pagination {
        .el-pager {
            .number {
                margin: 0px !important;
                background: #ffffff !important;
                border: 1px solid rgba(209, 219, 229, 1);
                color: #546374 !important;
                font-weight: 400;
                border-left: none
            }

            li.active {
                background-color: #409EFF !important;
                color: #fff !important;
                border-radius: 0px !important;
                width: 29px !important;
                height: 28px !important;
                border: solid 1px #409EFF !important;
            }

            li {
                border-radius: 0px !important;
            }
        }

        .btn-prev,
        .btn-next {
            margin: 0px !important;
            background: #ffffff !important;
            border: 1px solid rgba(209, 219, 229, 1);

        }

        .btn-prev {
            border-top-right-radius: 0px !important;
            border-bottom-right-radius: 0px !important;
        }

        .btn-next {
            border-top-left-radius: 0px !important;
            border-bottom-left-radius: 0px !important;
        }

        .btn-next {
            border-left: none;
        }
    }

    // 下拉选
    .el-select-dropdown__item.hover,
    .el-select-dropdown__item:hover {
        background-color: #55a8fd !important;
        color: #ffffff !important;
    }

    .el-select-dropdown__list {
        padding-top: 0px !important;
        padding-bottom: 0px !important;
        font-size: 14px !important;
        font-family: PingFang-SC-Regular !important;
        font-weight: 400;
    }

    .popper__arrow {
        display: none !important;
    }

    .chooseClass {
        .el-button:focus {
            background: rgba(85, 168, 253, 1) !important;
            color: #fff !important;
        }

        .el-button:hover {
            background: rgba(85, 168, 253, 1) !important;
            color: #fff !important;
        }

    }

    // 日历
    .el-picker-panel__body {
        font-family: PingFang-SC-Regular !important;
    }

    @import url('../../src/assets/less/override-element-ui.less');

</style>
